<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>轮次信息</title>
<style type="text/css">

</style>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-all.css"></link>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/xtheme-slate.css"></link>
<script src="../ext/adapter/ext/ext-base.js"></script>
<script src="../ext/ext-all.js"></script>
<script src="../ext/src/locale/ext-lang-zh_CN.js"></script>	
<script src="../ext/base/PagingMemoryProxy.js"></script>	
<script type="text/javascript">
Ext.onReady(function(){
	Ext.Ajax.on('requestcomplete',checkUserSessionStatus, this);      
	function checkUserSessionStatus(conn,response,options){      
	    if(response.getResponseHeader('sessionstatus')){      
	    	parent.location.href='/xdj/index.jsp';   
	    }      
	}  
	Ext.BLANK_IMAGE_URL='ext/resources/images/default/s.gif';
	
	var classStore = new Ext.data.JsonStore({
		url : "../base/class_load",
		autoLoad : true,
		fields : [ "id", "name" ]
	});
	var lineStore = new Ext.data.JsonStore({
		url : "../check/chkline_load",
		autoLoad : true,
		fields : [ "lineID", "lineName" ]
	});
	//表格
	//var sm = new Ext.grid.CheckboxSelectionModel();//列的复选框
	var cm=new Ext.grid.ColumnModel([
		new Ext.grid.RowNumberer(),  //自动增加序列号
		//sm, //加到每列的前边
		{header:'线路名称',dataIndex:'lineName',sortable:true}, //True表示为可在该列上进行排列
		{header:'值班名称',dataIndex:'claName'},
		{header:'轮次序号', dataIndex:'turnOrder'},
		{header:'起始时间',dataIndex:'startTime'},
		{header:'终止时间',dataIndex:'endTime'},
		{header:'备注',dataIndex:'remark'},
		{header:'classID',dataIndex:'classID',hidden:true},
		{header:'chkLineID',dataIndex:'chkLineID',hidden:true},
		{header:'turnID',dataIndex:'turnID',hidden:true}
	]);//定义相应的列模型


	var store=new Ext.data.JsonStore({
		url: 'turn_load',
	    root: 'result',
	   	// idProperty:'id',
	    totalProperty:'totalProperty',
	    fields: ["turnID", "turnOrder","startTime","endTime","remarks", "classID","claName","chkLineID","lineName"]
	});//存储前两项的定义的东西，将其连接起来
	
	var panel = new Ext.grid.GridPanel({
		region:'center',
		border:false,
		cm:cm,
		//sm:sm,
		store:store,
		height:document.body.clientHeight,  //设置表格的高度 true为自动获取表格的大小
		//renderTo:'grid' , //渲染容器
		enableColumnMove:false,//不可以使表格列移动
		enableColumnResize:false, //不可以改变列的宽度
		stripeRows:false, //True表示为显示行的分隔符
		loadMask:true,  //会有一个Ext.LoadMask的遮罩效果
		trackMouseOver : true,  //True表示为鼠标移动时高亮显示（默认为true）。
		enableDragDrop : true,
		viewConfig:{
			forceFit:true //让没列自动填满表格，根据你设置的宽度按比例分配
		},
		tbar:[{
	    	text: "删除",disabled:true,id:'cDeleteBox',
	    	icon:'../image/public/user_delete.png',
	    	handler:function() {
	    		var record=panel.getSelectionModel().getSelected();
	    		if(record==null){
					alert("请您选择要删除的轮次");
					Ext.getBody().unmask();
				}else{
					Ext.Ajax.request({
						url:'turn_delete',
						success:function(response){
							var result = Ext.util.JSON.decode(response.responseText);
							if(result.success==true){
								store.load({});
							}else{
								Ext.Msg.alert("提示","操作失败，请重试。") ;
							}
						},
						params:{turnId:record.get("turnID")}
					});
				}
				
	    	}
		},{
			text: "修改",disabled:true,id:'cModifyBox',
			icon:'../image/public/user_edit.png',
			handler:function() {
				var record=panel.getSelectionModel().getSelected();
				if(record==null){
					alert("请您选择要修改的轮次");
					Ext.getBody().unmask();
				}else{
					Ext.getBody().mask();
	        		showWindown("turn_update");
	        		form.getForm().setValues({
	        			"turn.line.chkLineID" : record.get("chkLineID"),
	        			"turn.classDuty.classID": record.get("classID") ,
	        			"turn.turnOrder": record.get("turnOrder") ,
	        			"startTime" : record.get("startTime"),
	        			"endTime" : record.get("endTime"),
	        			"turn.remarks": record.get("remarks"),
	        			"turn.turnID": record.get("turnID")
	        		});
				}
				
			}
			
		},{
	    	text: '增加',disabled:true,id:'cAddBox',
	    	icon:'../image/public/user_add.gif',
	        handler:function(){
	        	Ext.getBody().mask();
	        	showWindown("turn_save");
	        }
		}],
		bbar:new Ext.PagingToolbar({
			pageSize : 10, //每页显示几条
			store : store,
			beforePageText:"当前第",   
            afterPageText:"页，共{0}页",   
            lastText:"尾页",   
            nextText :"下一页",   
            prevText :"上一页",   
            firstText :"首页",                           
	        displayInfo:true, 
	        displayMsg:'显示第{0}条数据到{1}条数据,一共有{2}条', 
	        emptyMsg:'没有记录'
		})
	});
	store.load({params:{start:0,limit:10}});//加载数据  注意，一旦使用了分页条， store.load();就必须在构造表格之后进行执行，否则将不起作用，并且将分页条和数据源关联，从而实现与表格共享数据模型

	//右面表单信息
function showWindown(urlString) {
	form=new Ext.form.FormPanel({
		frame:true,
		height:270,
		buttonAlign:'left',
		labelAlign:'right',
		layout:'form',
		items:[{
			layout:'column',
			items:[{
				layout:'form',
				labelWidth : 80,
				items:[{
					fieldLabel:'轮次序号',
					xtype:'textfield',
					allowBlank:false,
					blankText:'序号不能为空',
					name:'turn.turnOrder'
				}]	
			}]		
		},{
			layout:'column',
			items:[{
				layout:'form',
				labelWidth : 80,
				items:[{
					fieldLabel:'路线名称',
					width:150,
					xtype : 'combo',
					hiddenName : 'turn.line.chkLineID',
					emptyText : '--请选择--',
					forceSelection : true,
					listWidth : 90,
					store : lineStore,
					valueField : 'lineID',
					displayField : 'lineName',
					typeAhead : true,
					mode : 'local',
					triggerAction : 'all',
					selectOnFocus : true
				}]
			},{
				layout:'form',
				labelWidth : 80,
				items:[{
					fieldLabel:'值班名称',
					items:[{
						width:150,
						xtype : 'combo',
						hiddenName : 'turn.classDuty.classID',
						emptyText : '--请选择--',
						forceSelection : true,
						listWidth : 100,
						store : classStore,
						valueField : 'id',
						displayField : 'name',
						typeAhead : true,
						mode : 'local',
						triggerAction : 'all',
						selectOnFocus : true
					}]
				}]
			}]
		},{
			layout:'column',
			items:[{
				layout:'form',
				labelWidth : 80,
				items:[{
					fieldLabel:'起始时间',
					width:150,
					xtype:'timefield',
					format:'H:i:s',
					allowBlank:false,
					blankText:'时间不能为空',
					name:'startTime'
				}]	
			},{
				layout:'form',
				labelWidth : 80,
				items:[{
					fieldLabel:'终止时间',
					width:150,
					xtype:'timefield',
					format:'H:i:s',
					allowBlank:false,
					blankText:'时间不能为空',
					name:'endTime'
				}]
				
			}]		
		},{
			layout:'form',
			labelWidth : 80,
			items:[{
				fieldLabel:'备注',
				xtype:'textarea',
				width:300,
				height:25,
				grow:true, //可自动增长
				preventScrollbars:true,  //不显示那个下拉条 必须与grow一起用
				name:'turn.remarks'
			}]
			
		},{
			xtype:'hidden',
			name:'turn.turnID'
		}],
		buttons:[{
	    	text: "保存",
	    	cls:'buttonSave',
	        handler:function(){ 
	        form.form.submit({   
	        	waitMsg : ' ......',   
	            url:urlString, 
	            method:'post',   
	            success:function(form,action){   
	                //Ext.MessageBox.confirm('success', 'is success！');   
	                var result = Ext.util.JSON.decode(action.response.responseText);
	            	if(result.success==true) {
	            		if(urlString=="turn_save"){
	            			win.close();
	            			Ext.getBody().unmask();
	            			store.load({});
	            		}else if(urlString=="turn_update"){
	            			win.close() ;
	            			Ext.getBody().unmask();
	            			store.load({});
	            		}
	            		
	            	}else{
	            		Ext.Msg.alert("提示","操作失败，请重试。") ;
	            	} 
	             },   
	             failure:function(form,action){   
	                alert(action.failureType);   
	              }
	          }); 
	       }
	     },{
	            text: "取消",
	            handler:function(){ 
		           	win.close() ;
		           	Ext.getBody().unmask();
		        }
	        }]
	});
	var win=new Ext.Window({
		title:'登录',
		 width:600,
		 height:300,
		 items:[form],
		 xtype:'form',
		 listeners:{"beforedestroy":function(obj)
             { 
			 Ext.getBody().unmask();  
                // obj.show(); return false; 
              }
		}  
	});
	win.show();
}
	 new Ext.Viewport({  
		layout : 'border', // 使用border布局  
		border:false,
		items:[panel],
		listeners:{
			'beforerender' : function(cmp) {
				// set role
				var store=new Ext.data.JsonStore({
					url: '../system/role_loadFunc?funcCode=ControlTurn',
					autoLoad : true,
					fields: ["functioncode"]
				});
				store.load({
				    callback: function(records, options, success){
				    	var i=0;
				    	for(; i<records.length; i++) {
				    		var id = records[i].get("functioncode");
				    		//alert('d'+Ext.getCmp('56').text);
				    		if(Ext.getCmp(id)!=null) {
				    			Ext.getCmp(id).setDisabled(false);
				    		}
				        }
				    },
				    scope: store
				});
			}
		}
	 }); 
	 
});
</script> 	
</head>
<body>
<div id="tree"></div>
<div id="grid"></div>
</body>
</html>